package com.jdd.pedicure.service;


import com.jdd.pedicure.dao.StaffDao;
import com.jdd.pedicure.entity.Result;
import com.jdd.pedicure.entity.Staff;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service("staffservice")
public class StaffService {
    @Resource
    StaffDao staffdao;

    public Staff queryById(int id) {
        return staffdao.getOne(id);
    }

    public Result<Staff> queryAllfree(Result<Staff> result){
        Example<Staff> ex = Example.of(result.getExample());
        List<Staff> all = staffdao.findAll(ex);
        result.setData(all);
        return result;
    }
    public List<Staff> queryAll() {
        return staffdao.findAll();
    }
    public void deletes(List<Staff> ids){
        staffdao.deleteAll(ids);
    }
    public void delete(int id) {
        staffdao.deleteById(id);
    }

    public void saveOrUpdate(Staff staff) {
        staffdao.save(staff);
    }

    public Result<Staff> queryByPage(Result<Staff> result) {
        PageRequest request = new PageRequest(result.getPage() - 1, result.getLimit());
        Example<Staff> ex = Example.of(result.getExample());
        Page<Staff> all = staffdao.findAll(ex, request);
        result.setData(all.getContent());
        result.setCount((int) all.getTotalElements());
        return result;
    }
}
